gender <- factor(c(rep('Male',5),rep('Female',5)))
height <- c(10,5,12,10,2,7,6,12,9,4)
dat <- data.frame(gender,height)
tapply(dat$height,dat$gender,mean)
aggregate(height~gender,data=dat,mean)
by(dat$height,dat$gender,mean)
